package com.xyz.basesdk.utils;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

import com.xyz.basesdk.base.BaseApplication;

public class SpUtil {
	private Editor editor;
	private SharedPreferences sp;

    private SpUtil(){
        sp = PreferenceManager.getDefaultSharedPreferences(BaseApplication.getContext());
    }
    private static class SingletonHolder{
        private final static SpUtil instance=new SpUtil();
    }
    public static SpUtil getInstance(){
        return SingletonHolder.instance;
    }

	public boolean getBoolean(String key, boolean defValue) {
		return sp.getBoolean(key, defValue);
	}

	public void putBoolean(String key, boolean state) {
		editor = sp.edit();
		editor.putBoolean(key, state);
		editor.commit();
	}

	public String getString(String key, String defValue) {
		return sp.getString(key, defValue);
	}

	public void putString(String key, String value) {
		editor = sp.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public int getInt(String key, int defValue) {
		return sp.getInt(key, defValue);
	}

	public void putInt(String key, int value) {
		editor = sp.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public void putLong(String key, long value) {
		editor = sp.edit();
		editor.putLong(key, value);
		editor.commit();
	}

	public long getLong(String key, Long defValue) {
		return sp.getLong(key, defValue);
	}

	public void putFloat(String key, float value) {
		editor = sp.edit();
		editor.putFloat(key, value);
		editor.commit();
	}

	public float getFloat(String key, Float defValue) {
		return sp.getFloat(key, defValue);

	}

	public boolean contains(String key) {
		return sp.contains(key);
	}

	public void clear(){
		editor = sp.edit();
		editor.clear();
		editor.commit();
	}
}
